package Logic;

import javax.swing.JLabel;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;


/**
 * This is the ballLabel class.
 * It is extended by the Ball class.
 * Also this class extends JLanel and
 * implements MouseMotionListener, and MouseListener classes.
 *
 */
public class ballLabel extends JLabel implements MouseMotionListener, MouseListener {
	//int variables to hold balls position in JPanel
	public int x;
	public int y;
	
	public int origX;
	public int origY;


        /**
	 * Constructor for BallLabel
	 */
	public ballLabel() {
		this.addMouseMotionListener(this);
		this.addMouseListener(this);
		this.x = this.getX();
		this.y = this.getY();
		this.origX = this.getX();
		this.origY = this.getY();
	}

	/**
	 * This method returns x coordinate of the ball
         *
         * @return x
	 */
	public int getBallX(){
		return x;
	}

	/**
	 * This method returns y coordinate of the ball
         *
         * @return y
	 */
	public int getBallY(){
		return y;
	}

        /**
	 * This method updates the x coordinate of the label
         *
         * @param xInteger
	 */
	public void setLabelX(int x){
            this.setLocation(x,this.getY());
        }

        /**
	 * This method updates the y coordinate of the label
         *
         * @param y Integer
	 */
	public void setLabelY(int y){
		this.setLocation(this.getX(),y);
	}

	/**
	 * This method updates the x and y coordinates of the 
	 * ball when the mouse is released
         *
         * @param e MouseEvent
	 */
	public void mouseReleased(MouseEvent e) {
		this.x = this.getX();
		this.y = this.getY();
		this.origX = this.getX();
		this.origY = this.getY();
                
	}

	/**
	 * This method sets the original x position to be used after
	 * the label has been changed. set from the ball class
         *
         * @param x
	 */
	public void setOrigX(int x){
		this.origX = x;
	}

	/**
	 * This method sets the original y position to be used after
	 * the label has been changed. set from the ball class
	 */
	public void setOrigY(int y){
		this.origY = y;
	}

        /**
	 * This method returns the origX
	 * @return int label1.origX
	 */
	public int getOrigX(){
		return origX;
	}

        /**
	 * This method returns the origY
	 * @return int label1.origY
	 */
	public int getOrigY(){
		return origY;
	}

        /**
         * This method is what makes the drag and drop of the balls possible in
         * the ballPanel in the GUI.
         *
         * @param e      MouseEvent
         */
	public void mouseDragged(MouseEvent e) {
		this.setLocation(this.getX() + e.getX(), this.getY() + e.getY());
		this.x = this.getX();
		this.y = this.getY();
		this.origX = this.getX();
		this.origY = this.getY();		
	}

	/**
         * Unused methods brought in my the implementation of classes.
         */
	public void mouseMoved(MouseEvent e) {
	}
	public void mousePressed(MouseEvent e) {
	}
	public void mouseClicked(MouseEvent e) {
	}
	public void mouseEntered(MouseEvent e) {
	}
	public void mouseExited(MouseEvent e) {
	}

        /**
         * PaintComponent Method
         *
         * This method will call the super class paintComponent method.
         *
         * @param g Graphics
         */
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
	}
}
